﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
    //页面加载时获取用户发布的出售信息
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)//用户未登录，返回登录界面
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            MyDataDataContext db = new MyDataDataContext();
            //获取用户发布出售信息的记录
            var results = from r in db.SaleOfGoods
                          where r.UserID == Session["UserId"].ToString()
                          select new
                          {
                              r.GoodsID,
                              r.GoodsName,
                              r.GoodsPicture,
                              r.Price,
                              r.Type
                          };//映射需要显示的字段



            //设置GridView控件的数据源
            gvSaleOfGoods.DataSource = results;
            //调用DataBind()方法显示信息
            gvSaleOfGoods.DataBind();
        }
        
    }
}